/**
 * Created with WebStorm.
 * @Author: panda
 * @Date: 2022-05-18 09:26
 * @Description: 搜索模块数据请求
 */
import { createRequestClient } from './axios/request';
import { APISchema } from "@/api/axios/type";
import localCache from "@/utils/localCache";
import { HotTitle } from "@/api/model/video"

export interface Video {
  copyright: string,
  cover: string,
  createBy: string,
  createTime: string,
  categoryId: number
  detail: string,
  duration: number,
  id: number,
  likes: number,
  title: string,
  videoUrl: string,
  views: number,
  username: string,
  avatar: string
  videoSize: number
}

export class InitVideoList {
  videos: Array<Video> = [];
}

interface VideoSchema extends APISchema {
  getVideoCardInfo: {
    request: {
      page: string
    };
    response: {
      code: number,
      data: Array<Video>[]
      msg: string
    };
  };
  getVideoList: {
    request: {
      pageNum: string | number
      pageSize: string | number
    };
    response: {
      code: number,
      data: Array<Video>[]
      msg: string
    };
  };
  getVideoDetail: {
    request: {
      id: number
    };
    response: {
      code: number,
      data: Video
      msg: string
    };
  }
  deleteVideo: {
    request: {
      id: number
    };
    response: {
      code: number,
      msg: string
    };
  }
  modifyVideo: {
    request: {
      id: number
      copyright: string,
      cover: string,
      detail: string,
      duration: number,
      categoryId: number,
      title: string,
      videoUrl: string,
      videoSize: number
    };
    response: {
      code: number,
      data: {}
      msg: string
    };
  }
  postVideo: {
    request: {
      copyright: string,
      cover: string,
      detail: string,
      duration: number,
      id: number,
      likes: number,
      title: string,
      videoUrl: string,
      views: number,
      username: string,
      avatar: string
    };
    response: {
      code: number,
      data: {}
      msg: string
    };
  }
  getAllVideos: {
    request: {
      pageNum: number, pageSize: number, categoryId?: number, keyword?: string
    };
    response: {
      code: number,
      data: { rows: Array<Video>, total: number }
      msg: string
    };
  },
  getHotVideos: {
    request: {
      topic: string
    };
    response: {
      code: number,
      data: Array<HotTitle>
      msg: string
    };
  },
  getTopVideos: {
    request: {};
    response: {
      code: number,
      data: Array<Video>
      msg: string
    };
  }
}

export const videoApi = createRequestClient<VideoSchema>({
  baseURL: process.env.NODE_ENV === 'development'
    ? process.env.VUE_APP_API_HOST + ''
    : '',
  headers: { 'Content-Type': 'application/json' },
  apis: {
    postVideo: {
      method: 'POST',
      path: 'POST /videos',
      headers: { token: localCache.getCache('token') }
    },
    getAllVideos: {
      method: 'GET',
      path: '/videos',
      headers: {}
    },
    getVideoCardInfo: 'GET /video/getVideoList/:page',
    //暂时post
    getVideoList: 'POST /video/getSelfVideo',
    getVideoDetail: 'GET /videos/:id',
    getTopVideos: 'GET /videos/top',
    deleteVideo: {
      method: 'DELETE',
      path: 'DELETE /videos/:id',
      headers: { token: localCache.getCache('token') }
    },
    modifyVideo: {
      method: 'PUT',
      path: 'PUT /videos/:id',
      headers: { token: localCache.getCache('token') }
    },
    getHotVideos: "GET /videos/hot"
  }
});

// // 查询给定接口页面的视频卡片信息列表
// export function getVideoCardInfo (page: string) {
//   return $http({
//     url: '/video/getVideoList/' + page,
//     method: 'get',
//     headers: {
//       isToken: false
//     }
//   })
// }
